#ifndef GAME_HH // 如果GAME_HH未定义，防止头文件被多次包含 / If GAME_HH is not defined, prevent multiple inclusions of this header
#define GAME_HH // 定义GAME_HH，表示此头文件已包含 / Define GAME_HH to indicate this header is included

#include "Character.hh" // 包含角色头文件，定义了Character类（玩家和敌人） / Include Character header, defines Character class (player and enemies)
#include "Room.hh" // 包含房间头文件，定义了Room类（游戏场景） / Include Room header, defines Room class (game scenes)
#include <vector> // 包含向量库，用于存储房间、消息等列表 / Include vector library for storing lists of rooms, messages, etc.
#include <string> // 包含字符串库，用于处理文本数据 / Include string library for handling text data
#include <map> // 包含映射库，用于存储Creeper的爆炸倒计时 / Include map library for storing Creeper explosion countdowns

// Game类：管理整个游戏的状态和逻辑
// Game class: Manages the entire game state and logic
class Game {
private: // 私有成员：只有Game类内部可以访问 / Private members: Only accessible within the Game class
    Character* player; // 指向玩家角色的指针，表示当前玩家 / Pointer to the player character, represents the current player
    std::vector<Room*> rooms; // 存储特殊房间（如The End）的列表 / List storing special rooms (e.g., The End)
    Room* currentRoom; // 指向玩家当前所在房间的指针 / Pointer to the room the player is currently in
    bool gameOver; // 表示游戏是否结束（true表示结束） / Indicates if the game is over (true means game over)
    std::vector<std::string> messageLog; // 存储游戏消息（如事件、战斗信息）的列表 / List storing game messages (e.g., events, battle info)
    bool showPlayerStatus; // 是否显示玩家状态（生命值、攻击力等） / Whether to show player status (health, attack, etc.)
    bool showInventory; // 是否显示玩家背包（物品列表） / Whether to show player inventory (list of items)
    std::map<Character*, int> creeperCountdown; // 存储Creeper敌人的爆炸倒计时，映射Creeper指针到倒计时值 / Stores Creeper enemies' explosion countdowns, maps Creeper pointers to countdown values
    int stepsToEnd; // 到达The End所需的剩余步数 / Remaining steps needed to reach The End
    bool inVillage; // 表示玩家是否在村庄（村庄是安全区域） / Indicates if the player is in a village (safe area)
    int x, y; // 玩家当前坐标，决定所在房间的描述 / Player's current coordinates, determine room description
    unsigned turnCount; // 记录当前回合数，跟踪游戏进度 / Tracks the current turn number, monitors game progress

    // 私有函数：仅在Game类内部使用，定义在单独文件中
    // Private functions: Used only within Game class, defined in separate files
    void displayInterface(); // 显示游戏界面（玩家状态、敌人、物品等） / Display game interface (player status, enemies, items, etc.)
    bool handleInput(); // 处理用户输入（移动、攻击等） / Handle user input (movement, attack, etc.)

public: // 公有成员：其他代码可以访问 / Public members: Accessible by other code
    // 构造函数：创建游戏对象并初始化 / Constructor: Creates game object and initializes it
    Game();
    // 析构函数：清理游戏对象，释放内存 / Destructor: Cleans up game object, frees memory
    ~Game();
    // 运行游戏：主循环，显示界面并处理输入 / Run game: Main loop, displays interface and handles input
    void run();

    // 在其他文件中定义的方法 / Methods defined in other files
    void initializeGame(int mode); // 初始化游戏（生存或创造模式） / Initialize game (survival or creative mode)
    void loadGame(); // 从文件加载游戏状态 / Load game state from file
    void saveGame(); // 保存游戏状态到文件 / Save game state to file
    std::string getRoomDescription(int x, int y); // 根据坐标获取房间描述 / Get room description based on coordinates
    void spawnEnemies(); // 在当前房间随机生成敌人 / Randomly spawn enemies in current room
    void triggerRandomEvent(); // 触发随机事件（如找到物品或进入村庄） / Trigger random events (e.g., find item or enter village)
    void updateEnemySkills(); // 更新敌人技能（如Creeper爆炸） / Update enemy skills (e.g., Creeper explosion)
    void restInVillage(); // 在村庄休息，恢复生命值 / Rest in village, restore health
    void tradeWithVillager(); // 与村民交易物品 / Trade items with villager
    void clearScreen(); // 清空屏幕，刷新显示 / Clear screen to refresh display
    void addMessage(const std::string& msg); // 添加消息到消息日志 / Add message to message log
    bool validateInput(const std::string& input, int& choice, int maxChoice); // 验证用户输入是否有效 / Validate if user input is valid

    // 访问器函数：获取或设置私有成员的值 / Accessor functions: Get or set private member values
    Character* getPlayer() { return player; } // 获取玩家指针 / Get player pointer
    Room* getCurrentRoom() { return currentRoom; } // 获取当前房间指针 / Get current room pointer
    std::vector<Room*>& getRooms() { return rooms; } // 获取特殊房间列表 / Get list of special rooms
    bool isGameOver() const { return gameOver; } // 检查游戏是否结束 / Check if game is over
    void setGameOver(bool status) { gameOver = status; } // 设置游戏结束状态 / Set game over status
    std::vector<std::string>& getMessageLog() { return messageLog; } // 获取消息日志 / Get message log
    bool isInVillage() const { return inVillage; } // 检查是否在村庄 / Check if in village
    void setInVillage(bool status) { inVillage = status; } // 设置村庄状态 / Set village status
    int getX() const { return x; } // 获取X坐标 / Get X coordinate
    int getY() const { return y; } // 获取Y坐标 / Get Y coordinate
    void setX(int val) { x = val; } // 设置X坐标 / Set X coordinate
    void setY(int val) { y = val; } // 设置Y坐标 / Set Y coordinate
    int getStepsToEnd() const { return stepsToEnd; } // 获取剩余步数 / Get remaining steps to The End
    void setStepsToEnd(int steps) { stepsToEnd = steps; } // 设置剩余步数 / Set remaining steps to The End
    std::map<Character*, int>& getCreeperCountdown() { return creeperCountdown; } // 获取Creeper倒计时映射 / Get Creeper countdown map
    bool getShowPlayerStatus() const { return showPlayerStatus; } // 检查是否显示玩家状态 / Check if player status is shown
    void setShowPlayerStatus(bool status) { showPlayerStatus = status; } // 设置是否显示玩家状态 / Set whether to show player status
    bool getShowInventory() const { return showInventory; } // 检查是否显示背包 / Check if inventory is shown
    void setShowInventory(bool status) { showInventory = status; } // 设置是否显示背包 / Set whether to show inventory
    unsigned getTurnCount() const { return turnCount; } // 获取当前回合数 / Get current turn count
    void incrementTurnCount() { turnCount++; } // 增加回合数 / Increment turn count
};

#endif // GAME_HH // 结束头文件保护 / End header guard